﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "教学运行管理 - 学期课程安排 - 重建教师时间占用表");
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		
		termId = event.getArg("TID");

		sql = "SELECT 
					t.term_id, 
					t.academic_year, 
					t.academic_term, 
					t.term_prop 
				FROM 
					t_term t 
				WHERE 
					t.term_id = :termId ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		
		rs_term = queryObj.execute( sql=sql ).getResult();
		

		/* 生成可重建教师时间占用表的教学班列表 */
		taskArray = [];
		
		sql = "SELECT 
					tsk_id, 'P' task_type 
					FROM t_task 
					WHERE 
						term_id = :termId AND task_time is not null 
				UNION ALL 
				SELECT 
					tsk_id, 'C' task_type 
					FROM t_common_task 
					WHERE 
						term_id = :termId AND task_time is not null 
				UNION ALL 
				SELECT 
					tsk_id, 'T' task_type 
					FROM t_sport_task 
					WHERE 
						term_id = :termId AND task_time is not null 
				UNION ALL 
				SELECT 
					tsk_id, 'R' task_type 
					FROM t_reopen_task 
					WHERE 
						term_id = :termId AND task_time is not null ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		
		rs_task_arranged = queryObj.execute( sql=sql ).getResult();
		
		for ( a=1; a lte rs_task_arranged.recordCount; a++ ) {
			arrayAppend( taskArray, [ rs_task_arranged["tsk_id"][a], rs_task_arranged["task_type"][a] ] );
		}
		
		
		
		passArgs = structNew();
		
		structInsert( passArgs, "TID", termId, true );
		
		currentTab = event.getArg("Tab", "labRebuild");

	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 db"></i><cfoutput>#rs_term.academic_year#</cfoutput> 学年 - <cfoutput>#dictAdvice.getTerm(rs_term.academic_term)#</cfoutput> 教师时间占用表
				</h2>
			</div>
		</div>
	</div>
</div>

<!--- 加载导航菜单 --->
<!-- stepMenu-->
<cfoutput>#event.getArg("stepMenu")#</cfoutput>
<!--/stepMenu-->

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
			
				<div class="UItab2">
					<div class="tabLables">
						<span <cfif currentTab eq "labRebuild">class="active"</cfif> id="labRebuild" tabTarget="Rebuild">重建数据</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Rebuild" class="tabContent">
					
					<div class="noticeBlock">
						<h3>重建教师时间占用表</h3>
						<p>
							<span class="img icon16x16 message"></span>
							此项功能可帮助您根据排课结果重建教师时间占用数据. 
							只有当前系统采用了第三方排课数据接口 或 手工导入排课数据时, 才需要对教师时间占用表数据进行重建.
						</p>
						<hr/>
					</div>
					
					<cfif arrayLen(taskArray)>
						<form id="formRebuild" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('rebuildTeacherTimeTable', passArgs)#</cfoutput>">
						
							<div class="label">
								<b>学时相关</b>
								<input name="flushPriod" id="flushPriod" type="checkbox" class="typeCheckbox" checked="checked" value="1" /> 刷新已排学时数
							</div>
						
							<div class="lable">
								<input id="trigger" class="button1" type="button" value="重建缓存" />
							</div>
						
						</form>
					
						<div id="doRebuilding" class="hidden_elem">
								
							<div class="mtl mbs">
								<img src="<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/graphic/waiting.gif" />
							</div>
					
							<div class="UIProgressbar">
								<span class="progressBar" id="pb1">0%</span>
								<p id="output">处理队列初始化</p>
								<p id="info"></p>
							</div>
						
						</div>
						
						<div id="rebuildComplete" class="clearfix hidden_elem">
							
							<ul class="UIDashBoard">
								<li class="col2">
									<div class="board hasPic">
										<a href="<cfoutput>#buildURL('taskSummary', passArgs)#</cfoutput>">
											<div class="pic">
												<span class="icon48x48 teacherCourseTable"></span>
											</div>
											<div class="content">
												<h3>Progress<span class="unitPriod">COMPLATE</span></h3>
												<h5>教师时间占用表</h5>
												<p class="describ">教师时间占用缓存已重建完成, 请返回排课页面继续操作</p>
											</div>
										</a>
									</div>
								</li>
							</ul>
							
						</div>
						
						<div id="out"></div>
					
						<script language="javascript" type="text/javascript">
							//<![CDATA[
							<!--
							
							var taskArray = [ <cfloop from="1" to="#arrayLen(taskArray)#" index="i">['<cfoutput>#taskArray[i][1]#</cfoutput>','<cfoutput>#taskArray[i][2]#</cfoutput>']<cfif i lt arrayLen(taskArray)>, </cfif></cfloop>]

							$(document).ready(function() {
								
								$("#trigger").click(function(){
									
									processRebuild();
									
								});
								
							});
							
							function processRebuild() {
								
								$("#formRebuild").addClass("hidden_elem");
								$("#doRebuilding").removeClass("hidden_elem");
								
								/* 显示阻挡信息 */
								$.blockUI({ 
											message: '正在重建缓存...请耐心等待',
											css: { 
													'width': '16%',
													'left': '42%',
													'border': 'none', 
													'padding': '15px 5px', 
													'backgroundColor': '#333', 
													'border-radius': '4px', 
													'opacity': .6, 
													'color': '#fff',
													'cursor': null
													},
											overlayCSS: {
													'backgroundColor': '#aaa', 
													'opacity': .1 ,
													'cursor': null
													}
											});	
								
								/* init Progress */
								$("#pb1").progressBar({
														boxImage		: '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbar.gif',
														barImage		: {
																			0:  '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_red.gif',
																			30: '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_orange.gif',
																			70: '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_green.gif'
																			}
														});
								
								/* 开始序列处理 */
								progressThread(0);
								
							}
							
							function progressThread(current) {
								
								var taskId = taskArray[current][0];
								var taskType = taskArray[current][1];
								
								$.post(
										"<cfoutput>#buildURL('apiTaskRebuild')#</cfoutput>", 
										{
											'TSK': taskId,
											'TT': taskType,
											'PAR': 'TEACHER_TIMETABLE',
											'seed': (new Date()).getTime()
										}, 
										function(data) {

												//$("#out").html(data);
												response = $.parseJSON(data);
												
												$("#output").html( "PROC-" + current + "/" + taskArray.length + ". " + response.operation );
												
												/* fresh progress bar */
												var percentage = Math.floor(100 * parseInt(current + 1) / parseInt(taskArray.length));
												
												$("#pb1").progressBar(
																		percentage,
																		{
																			boxImage : '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbar.gif',
																			barImage : {
																				0:  '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_red.gif',
																				30: '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_orange.gif',
																				70: '<cfoutput>#getProperty('cdnServer')#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_green.gif'
																			},
																			callback: function(running){
																	
																				if (running.running_value == running.value) {
																	
																					current++;
											
																					if ( current < taskArray.length) {
																						progressThread(current);
																					}
																					else {
																				
																						$("#output").text("完成");
																						$("#rebuildComplete").removeClass("hidden_elem");
																						$("#doRebuilding").addClass("hidden_elem");
																						
																						/* 取消阻挡 */
																						$.unblockUI();
																					}
																				}
																			}
																	
																		});
												
										});
								
								

							}
							
							// -->
							//]]>
						</script>	
					
					</cfif>
					
				</div>

			</div>
		</li>
	</ul>
</div>